package com.mall.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisUtil {
	private RedisUtil(){
		
	}
	private static JedisPool jedisPool=null;
	public static JedisPool getJedis(){
			if(jedisPool==null){
				synchronized (RedisUtil.class) {
					if(jedisPool==null){
						JedisPoolConfig poolConfig=new JedisPoolConfig();
						poolConfig.setMaxTotal(1000);
						poolConfig.setMaxIdle(30);
						poolConfig.setMaxWaitMillis(100*1000);
						poolConfig.setTestOnBorrow(true);
						jedisPool=new JedisPool(poolConfig, "192.168.153.102", 6379);
					}
				}
			}
			return jedisPool;
	}
	public static void close(JedisPool jedisPool,Jedis jedis){
			if(jedis!=null){
				jedisPool.returnResourceObject(jedis);
			}
	}
}
